package birdsVSZombiesClient.gameGraphic;

import java.util.ArrayList;

import processing.core.PApplet;
import processing.core.PImage;
import processing.core.PVector;

/**
 * @author yangliu
 *	The class for the effects like collision explode.
 *	In the client, there is an arraylist stores all these animation objects.
 */
//public class BVZCollisionAnimation extends Thread {
public class BVZCollisionAnimation{
	public static PApplet parent;
	public static PImage[] animationImages;
	public static int animationTotalImages;
	public int animationTotalFrame;
	public int animationCurrentFrame;
	public float animationFrameRate;
	public int animationType;
	public int animationStage;
	public PVector animationPosition;
	
	public boolean isRunning;
	public boolean isEnd;
	
	public BVZCollisionAnimation(float frameRate, PVector pos){
		
		this.isRunning = false;
		this.isEnd = false;
		
		this.animationTotalFrame = 6;
		this.animationCurrentFrame = 0;
		this.animationFrameRate = frameRate;
		
		this.animationPosition = pos;
		
	}
	
	public void start(){
		this.isRunning = true;
//		super.start();
	}
	
	public void run(){
//		while(isRunning && animationCurrentFrame < animationTotalFrame){
		if(isRunning && animationCurrentFrame < animationTotalFrame){
			parent.image(animationImages[animationCurrentFrame], animationPosition.x, animationPosition.y);

			animationCurrentFrame++;
			
//			try {
//				sleep((long)(1/animationFrameRate));
//			} catch (Exception e) {
//				// TODO: handle exception
//			}
//		}
		}
		else if(isRunning && animationCurrentFrame >= animationTotalFrame){
			end();
		}
	}
	
	public void end(){
		isRunning = false;
		isEnd = true;
//		interrupt();
	}
}
